package com.zblwyj.service;

import com.zblwyj.bean.User;
import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.amqp.rabbit.connection.CorrelationData;
import org.springframework.amqp.utils.SerializationUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.UUID;


@Service
public class SendMsgService {

    @Autowired
    private AmqpTemplate amqpTemplate;

    public void sendMsg(String message){
        // 发送字符串

        // 发送消息到某个队列
        amqpTemplate.convertAndSend("wfx-quence", message);
 /*       // 发送消息到订阅交换机
        amqpTemplate.convertAndSend("fanoutExchange", "", message);
        // 发送消息到路由交换机
        amqpTemplate.convertAndSend("directExchange", "rk1", message);

        // 发送对象： 可以用jdk序列化 也可以用json字符串发送
        User user = new User();
        user.setAddress("四川");
        user.setName("为一级");
        byte[] serialize = SerializationUtils.serialize(user);
        // 发送消息到某个队列
        amqpTemplate.convertAndSend("wfx-quence", serialize);
        // 发送消息到订阅交换机
        amqpTemplate.convertAndSend("fanoutExchange", "", serialize);
        // 发送消息到路由交换机
        amqpTemplate.convertAndSend("directExchange", "rk1", serialize);*/


    }
}